html_doc = """
<html><head><title>The Dormouse's story</title></head>
    <body>
        <p class="title" ><b>The Dormouse's story</b></p>
        <p class="story">0nce upon a time there were three little sisters; and their nanes were
        <a href="http://example.com/elsie" class=" sister" id="link1">Elsie</a>,
        <a href- "http://example . com/lacie" class="sister" id=" link2">Lacie</a> and
        <a href= "http://example. com/tillie" class="sister" id=" link3">Tillie</a>;
        and they lived at the bottom of a well. 
    </p>

<p class-" story">...</p>
"""
#使用bs4格式化输出代码
from bs4 import BeautifulSoup
soup=BeautifulSoup(html_doc,'lxml')
# # print(soup.prettify())
# #了解即可
# print(soup.p)#soup.标签名（只找一个）
# print(soup.title.name)#soup.标签名.name（获取标签名）
# print(soup.title.string)#soup.标签名.string（获取标签内容）
# print(soup.p['class'])#soup.标签名[属性名]（获取属性值）

#重点掌握
print(soup.find('a',id=" link2")) #soup.find(标签名,id属性)（精确查找）
print(soup.find_all('a'))#以列表的形式返回所有a标签